<template>
    <div class="newsinfo-container">
        <!-- 标题区 -->
        <h3 class="title">{{ newsInfo.title }}</h3>
        <p class="subtitle">
            <span>发表时间：{{ newsInfo.dateAdd }}</span>
            <span>浏览次数：{{ newsInfo.views }}</span>
        </p>
        <hr>

        <!-- 内容区 -->
        <div class="content" v-html="newsInfo.content"></div>

        <!-- 评论区 -->
        <comment :refId="id"></comment>
    </div>
</template>

<script>
    //导入评论子组件
    import comment from "../subcomponents/Comment.vue"

    export default {
        data() {
            return {
                id: this.$route.query.id,
                newsInfo: ''
            }
        },
        created() {
           this.getNewsInfo() 
        },
        components:{
            comment
        },
        methods: {
            getNewsInfo() {
                this.$http.get('/cms/news/detail',{
                    params: {
                        id: this.id
                    }
                }).then( (res) => {
                    if( res.data.code === 0 ) {
                        this.newsInfo = res.data.data
                    }else{
                        this.$toast(res.data.msg)
                    }
                })
            }
        }
    }
</script>

<style lang="scss">
.newsinfo-container{
    width: 100%;
    padding: 10px 5px;
    .title{
        font-size: 16px;
        text-align: center;
        line-height: 20px;
        padding-bottom: 5px;
    }
    .subtitle{
        display: flex;
        justify-content: space-between;
        span{
            font-size: 12px;
            color: #666;
        }
    }
    .content{
        width: 100%;
        img{
            width: 100%;
        }
        p{
            font-size: 14px !important;
            margin-bottom: 15px !important;
            line-height: 22px !important;
        }
    }

}
</style>